package com.aaa.gs.service.impl;

import com.aaa.common.entity.ProductReviewImage;
import com.aaa.gs.dao.ProductReviewImageDao;
import com.aaa.gs.service.ProductReviewImageService;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.aaa.common.util.CustomException;
import com.aaa.common.util.ResultStatus;
import com.aaa.common.vo.Page;


import javax.annotation.Resource;

/**
 * (ProductReviewImage)表服务实现类
 *
 * @author makejava
 * @since 2025-10-10 17:34:13
 */
@Service("productReviewImageService")
public class ProductReviewImageServiceImpl implements ProductReviewImageService {
    @Resource
    private ProductReviewImageDao productReviewImageDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ProductReviewImage queryById(Integer id) {
        return this.productReviewImageDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param page 筛选条件
     * @return 查询结果
     */
    @Override
    public PageInfo queryByPage(Page<ProductReviewImage> page) {
        //分页操作  分页参数一定要进行传递
        if (page == null || page.getPageNo() == null || page.getPageNo() == 0 || page.getPageSize() == null || page.getPageSize() == 0) {
            //进行业务编写时，可以抛出自定义异常
            throw new CustomException(ResultStatus.PARAM_NOT_EMPTY.getReturnCode(),
                    ResultStatus.PARAM_NOT_EMPTY.getReturnMessage());
        }
        PageHelper.startPage(page.getPageNo(), page.getPageSize());
        //获取查询对象
        ProductReviewImage productReviewImage = page.getData();
        return new PageInfo(productReviewImageDao.queryAllByLimit(productReviewImage));
    }

    /**
     * 新增数据
     *
     * @param productReviewImage 实例对象
     * @return 实例对象
     */
    @Override
    public ProductReviewImage insert(ProductReviewImage productReviewImage) {
        this.productReviewImageDao.insert(productReviewImage);
        return productReviewImage;
    }

    /**
     * 修改数据
     *
     * @param productReviewImage 实例对象
     * @return 实例对象
     */
    @Override
    public ProductReviewImage update(ProductReviewImage productReviewImage) {
        this.productReviewImageDao.update(productReviewImage);
        return this.queryById(productReviewImage.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.productReviewImageDao.deleteById(id) > 0;
    }
}
